package com.universityJob.common.utils;

/**
 * @author mao on 2021/5/18.
 * @version 1.0 maozhijob@163.com
 */

import org.apache.commons.collections.MapUtils;

import java.util.Map;

public class Pageable {
    private Integer page;
    private Integer pageSize;
    private static final Integer PAGE_DEFAULT = 1;
    private static final Integer PAGE_SIZE_MAX = 2147483647;

    private Pageable(Integer page, Integer pageSize) {
        this.page = page;
        this.pageSize = pageSize;
    }

    public static Pageable createPage(Integer page, Integer pageSize) {
        return new Pageable(page, pageSize);
    }

    public static Pageable createPage(Object page, Object pageSize) {
        Integer pageNum;
        try {
            pageNum = (Integer)page;
        } catch (Exception var6) {
            pageNum = PAGE_DEFAULT;
        }

        Integer sizeNum;
        try {
            sizeNum = (Integer)pageSize;
        } catch (Exception var5) {
            sizeNum = PAGE_SIZE_MAX;
        }

        return new Pageable(pageNum, sizeNum);
    }

    public static Pageable createPage(Map param) {
        Integer pageNum;
        try {
            String page = MapUtils.getString(param, "page", "1");
            pageNum = Integer.parseInt(page);
        } catch (Exception var5) {
            pageNum = PAGE_DEFAULT;
        }

        Integer sizeNum;
        try {
            String rows = MapUtils.getString(param, "rows", "15");
            sizeNum = Integer.parseInt(rows);
        } catch (Exception var4) {
            sizeNum = PAGE_SIZE_MAX;
        }

        return new Pageable(pageNum, sizeNum);
    }

    public Integer getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPage() {
        return this.page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }
}
